extends Node
class_name TileMapUtil

static var hight_light_move_path_cell_16_h: Vector2i = Vector2i(0, 1)
static var hight_light_move_path_cell_8_h: Vector2i = Vector2i(1, 1)
static var hight_light_move_path_cell_4_h: Vector2i = Vector2i(2, 1)
static var hight_light_move_path_cell_0_h: Vector2i = Vector2i(3, 1)

static var hight_light_move_range_cell_16_h: Vector2i = Vector2i(0, 0)
static var hight_light_move_range_cell_8_h: Vector2i = Vector2i(1, 0)
static var hight_light_move_range_cell_4_h: Vector2i = Vector2i(2, 0)
static var hight_light_move_range_cell_0_h: Vector2i = Vector2i(3, 0)

static var hight_light_move_path_cell_up_slop: Vector2i = Vector2i(1, 3)
static var hight_light_move_path_cell_down_slop: Vector2i = Vector2i(2, 3)
static var hight_light_move_path_cell_left_slop: Vector2i = Vector2i(0, 3)
static var hight_light_move_path_cell_right_slop: Vector2i = Vector2i(3, 3)

static var hight_light_move_range_cell_up_slop: Vector2i = Vector2i(1, 2)
static var hight_light_move_range_cell_down_slop: Vector2i = Vector2i(2, 2)
static var hight_light_move_range_cell_left_slop: Vector2i = Vector2i(0, 2)
static var hight_light_move_range_cell_right_slop: Vector2i = Vector2i(3, 2)
	
static func convert_layer_coordinate_2_globle_p(_cell:Vector2i, tileMapLayer:TileMapLayer) -> Vector2:
	# 将TileMapLayer中的坐标值转换成全局向量
	var layer_local_pos: Vector2 = tileMapLayer.map_to_local(_cell)
	var gloal_pos: Vector2 = tileMapLayer.to_global(layer_local_pos)
	return gloal_pos



static func convert_globle_p_2_layer_cell(_gloal_position:Vector2, tileMapLayer:TileMapLayer) -> Vector2i:
	# 将全局向量转换成TileMapLayer中的坐标值
	var layer_local_pos: Vector2 = tileMapLayer.to_local(_gloal_position)
	var cell: Vector2i = tileMapLayer.local_to_map(layer_local_pos)
	return cell


static func _get_attack_high_light_cell(cell:Vector2i, tile_map_layer:TileMapLayer) -> Vector2i:
	var tile_data:TileData = tile_map_layer.get_cell_tile_data(cell)
	if not tile_data:
		push_error("当前cell无地块")
	var y_offset:int = tile_data.get_custom_data("y_offset")
	var type:String = tile_data.get_custom_data("type")
	if type.contains("Slope"):
		if type.contains("Up"):
			return hight_light_move_range_cell_up_slop + Vector2i(0, 1)
		if type.contains("Down"):
			return hight_light_move_range_cell_down_slop + Vector2i(0, 1)
		if type.contains("Left"):
			return hight_light_move_range_cell_left_slop + Vector2i(0, 1)
		if type.contains("Right"):
			return hight_light_move_range_cell_right_slop + Vector2i(0, 1)
		push_error("type ", type, " 没有对应的移动高亮cell")
		return Vector2i(-1, -1)

	match y_offset:
		0:
			return hight_light_move_range_cell_16_h + Vector2i(0, 1)
		8:
			return hight_light_move_range_cell_8_h + Vector2i(0, 1)
		12:
			return hight_light_move_range_cell_4_h + Vector2i(0, 1)
		16:
			return hight_light_move_range_cell_0_h + Vector2i(0, 1)
	push_error("y_offset ", y_offset, " 没有对应的移动高亮cell")
	return Vector2i(0, -1)
